<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
  <cpn></cpn>
</div>
<template id="cpn">
  <div>
    <ccpn></ccpn>
  </div>
</template>
<template id="ccpn">
  <div>
    <h2>我是ccpn组件</h2>
    <button @click="ccbtnClick">按钮</button>
  </div>
</template>
<script src="../js/vue.js"></script>
<script>
  /**
   * 组建通信  子组件访问父组件 $parent
   * 子组件访问 root根组件就是 vue实例对象 $root
   */
  const app=new Vue({
    el: '#app',
    data: {
      message:'你好vue',
    },
    methods: {
    },
    components: {
      cpn: {
        template: '#cpn',
        data(){
          return {
            name: '我是cpn组件的name属性'
          }
        },
        components: {
          ccpn: {
            template: '#ccpn',
            methods: {
              ccbtnClick(){
                console.log("ccbtnClick");
                console.log(this.$parent);
                console.log(this.$parent.name);
                console.log(this.$root);
                console.log(this.$root.message);

              }
            }
          }
        }
      }
    }
  })
</script>
</body>
</html>